package leetcode.code007;

/**
 * 求余取数
 *
 * @author CaoYu
 * @date 2021年8月10日
 * @description
 */
public class Solution2 implements ISolution {
	public static void main(String[] args) {
		int x = 123;
		int y = 120;
		int z = -120;
		int k = 1534236469;

		print(x, new Solution2());
		print(y, new Solution2());
		print(z, new Solution2());
		print(k, new Solution2());
	}

	public static void print(int x, ISolution isolution) {
		int result = isolution.reverse(x);
		System.out.println(result);
	}

	@Override
	public int reverse(int x) {
		int a = 0;
		long res = 0;
		while (x != 0) {
			a = x % 10;
			x = x / 10;
			res = res * 10 + a;
		}
		if (res > Integer.MAX_VALUE || res < Integer.MIN_VALUE)
			return 0;
		return (int) res;
	}

}
